/**
 *
 * ......................我佛慈悲.......................
 *                       _oo0oo_
 *                      o8888888o
 *                      88" . "88
 *                      (| -_- |)
 *                      0\  =  /0
 *                    ___/`---'\___
 *                  .' \\|     |// '.
 *                 / \\|||  :  |||// \
 *                / _||||| -卍-|||||- \
 *               |   | \\\  -  /// |   |
 *               | \_|  ''\---/''  |_/ |
 *               \  .-\__  '-'  ___/-. /
 *             ___'. .'  /--.--\  `. .'___
 *          ."" '<  `.___\_<|>_/___.' >' "".
 *         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *         \  \ `_.   \_ __\ /__ _/   .-` /  /
 *     =====`-.____`.___ \_____/___.-`___.-'=====
 *                       `=---='
 *
 *..................佛祖开光 ,永无BUG....................
 *         CSDN博客:http://blog.csdn.net/song5347
 *       github地址:https://github.com/lingsuiderongyan
 *             邮箱:lingsuiderongyan@163.com
 */

import UIKit

class LSMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //  全局设置UITabbar的tintColor, 执行的越早越好,一般会放到appdelegate里面
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        //设置自定义的TabBar
        let lsTabBar = LSTabBar()
        
        //设置代理对象
        lsTabBar.lsDelegate = self
        
        lsTabBar.compostButtonClosure = { [weak self] in
            //进入发微博界面
            self?.pushComposeVC()
        }

        //使用kvc方式给系统的只读属性设置值
        setValue(lsTabBar, forKey: "tabBar")

        //添加子视图控制器
        addChildViewController(LSHomeViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(LSMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(LSDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(LSProFileTableViewController(), imageName: "tabbar_profile", title: "我的")
    }
    
    
    //重载添加自控制的函数
    func addChildViewController(childController: UIViewController, imageName: String, title: String) {
        //设置图片
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置标题
        childController.title = title
        
        //设置文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        //设置文字大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14)], forState: UIControlState.Normal)
        
        //添加到导航控制器
        let nav = UINavigationController(rootViewController: childController)
        
        //给当前对象添加子视图控制器
        addChildViewController(nav)  //没有这行代码,标题不显示
    }
    
    //MARK: - 进入发微博界面
    private func pushComposeVC() {
        
        let composeVC = LSComposeViewController()
        
        let nav = UINavigationController(rootViewController: composeVC)
        
        presentViewController(nav, animated: true, completion: nil)
    }
}

extension LSMainViewController: LSTabBarDelegate {
    
    //实现代理方法
    func didSelectedComposeButton() {
        
        print("我是对象调过来的")
        
    }
    
}






















